<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="报名人员" prop="applicantName">
        <el-input v-model="queryParams.applicantName" placeholder="请输入" clearable style="width: 200px" />
      </el-form-item>
      <el-form-item label="报名岗位" prop="postId">
        <el-select multiple v-model="form.postId" placeholder="请选择">
          <el-option v-for="dict in postList" :key="dict.postId" :label="dict.postName" :value="dict.postId"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="审批类型" prop="approveId">
        <el-select multiple v-model="form.approveId" placeholder="请选择">
          <el-option
            v-for="dict in examPerList"
            :key="dict.libId"
            :label="dict.libTitle"
            :value="dict.libId"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="报名时间" prop="applicationTime">
        <el-date-picker v-model="form.applicationTime" type="date" placeholder="请选择" clearable
          value-format="YYYY-MM-DD" />
      </el-form-item>
      <el-form-item>
        <el-button color="#265DA4" :dark="isDark" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="examList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="left" type="index" width="100" />
      <el-table-column label="报名人员" align="left" prop="applicantName" />
      <el-table-column label="报名岗位" align="left" prop="postName">
      </el-table-column>
      <el-table-column label="考试批次" align="left" prop="batchName">
      </el-table-column>
      <el-table-column label="报名时间" align="left" prop="applicationTime">
      </el-table-column>
      <!-- <el-table-column label="审批类型" align="left" prop="approverName">
      </el-table-column> -->
      <el-table-column label="审批状态" align="left" prop="approveStatusName">
      </el-table-column>
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
        <template #default="scope">
          <!-- // 待审批是0 通过1 -->
          <el-button link  icon="" :disabled="scope.row.approveStatus"
            @click="handleApply('1', scope.row)">通过</el-button>
            
            <!-- <el-button link :style="{color:scope.row.approveStatus?'rgb(117 153 200)':'#265DA4'}" icon="" :disabled="scope.row.approveStatus"
            @click="handleApply('0', scope.row)">通过</el-button> -->

            <el-button link :disabled="!scope.row.approveStatus"
            @click="handleApply('0', scope.row)">不通过</el-button>
         
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script setup name="Place">
import { listPost } from "@/api/system/post";
import {
  examinationApproveList,
  examinationApproveEdit,
} from "@/api/application/apply";
const { proxy } = getCurrentInstance();

const examPerList = ref([]);
const examList = ref([]);
const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const postList = ref([]);

const data = reactive({
  form: {

  },
  queryParams: {
    pageSize: 10,
    pageNum: 1,
    applicantName: '',
    postId: '',
    approveId: '',
    applicationTime: '',
  },
  rules: {
    typeName: [
      { required: true, message: "考点名称不能为空", trigger: "blur" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);


/** 查询岗位列表 */
function getPostList() {
  listPost({
    pageSize: 100,
    pageNum: 1
  }).then(response => {
    postList.value = response.rows;
    total.value = response.total;
  });
}
/** 查询考点列表 */
function getList() {
  loading.value = true;
  examinationApproveList(queryParams.value).then((response) => {
    examList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 表单重置 */
function reset() {
  form.value = {
    libIds: "",
    typeName: "",
  };
  proxy.resetForm("noticeRef");
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.noticeId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}



function handleApply(type, row) {
  console.log(type, 'typw');
  let tip = type == '1' ? '是否确认通过' : '是否确认不通过';
  proxy.$modal
    .confirm(tip)
    .then(function () {
      examinationApproveEdit({
        approveId: row.approveId,
        approveStatus: type
      }).then((response) => {
        proxy.$modal.msgSuccess("更新成功");
        getList();
      });
    })
    .then(() => {
      getList();

    })
    .catch(() => { });

}

getPostList()
getList();
</script>
<style lang="scss" scoped>
:deep(.el-pagination.is-background .el-pager li:not(.is-disabled).is-active) {
  background-color: #265DA4 !important; //修改默认的背景色
}
.inputDeep {
  :deep(.el-input__inner) {
    width: 192px !important;
  }
}
</style>
